import axios from '../../axios/api'
import React from 'react'
import { useEffect } from 'react'
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'

function Home() {
    const [data, setData] = useState([])
    const navigate = useNavigate()

    const getData = async () => {
        const res = await axios.post('/api/trip/train', {
            "start": "北京",
            "end": "广州",
            "date": "string",
            "isSpeed": true,
            "isSeat": true,
            "isDesc": true,
            "page": 1
        })
        console.log(res);


        const { code, data } = res.data
        if (code == 200) {

            setData(data)

        }
    }
    useEffect(() => {
        getData()
    }, [])
    return (
        <div>
            <div >
                {
                    data.map((item, index) => {
                        return (
                            <div onClick={() => {
                                navigate('/detail?id=' + item.id)
                            }} key={index} style={{ display: 'flex', justifyContent: 'space-around' }}>
                                <div>
                                    <p>{item.start}</p>
                                </div>
                                <div>
                                    <p>{item.end}</p>
                                </div>
                            </div>
                        )
                    })
                }
            </div>
        </div>
    )
}

export default Home